package mlz.d_tcp1;

import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
    public static void main(String[] args) throws IOException {

        System.out.println("-----服务器启动成功-----");
        //1.新建serverSocket对象
        ServerSocket socket = new ServerSocket(8888);

        //2.使用serverSocket对象进行连接 -> 等待客户端连接成功
        Socket accept = socket.accept();

        //3.从socket中获取流对象 -> 读数据
        InputStream is = accept.getInputStream();

        //4.转换成数据流
        DataInputStream dis = new DataInputStream(is);

        //5.使用数据流读取客户端中发送过来的信息
        String s = dis.readUTF();
        System.out.println(s);
        System.out.println(accept.getRemoteSocketAddress());

        //关闭流对象
        dis.close();
        socket.close();
    }
}
